//
//  SLCertificationRequirementTableViewCell.m
//  SulitLoanDemo
//
//  Created by 虞嘉伟 on 2025/2/22.
//

#import "SLCertificationRequirementTableViewCell.h"
#import <YYKit.h>
#import <Masonry.h>


@interface SLCertificationRequirementTableViewCell ()
@property (nonatomic, strong) UIView *bgView;// 容器
@property (nonatomic, strong) UIImageView *decorate;
@property (nonatomic, strong) UIView *clauseView;
@end


@implementation SLCertificationRequirementTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = UIColor.clearColor;
        self.contentView.backgroundColor = UIColorHex(#F5F5F5);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.titleView];
        [self.contentView addSubview:self.bgView];
        [self.contentView addSubview:self.decorate];
        
        [self.bgView addSubview:self.iv];
        [self.bgView addSubview:self.title];
        [self.bgView addSubview:self.subtitle];
        [self.bgView addSubview:self.clauseView];
        
        [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.contentView).inset(20);
            make.top.equalTo(self.contentView);
            make.height.mas_equalTo(61);
        }];
        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.contentView).inset(20);
            make.top.equalTo(self.titleView.mas_bottom);
            make.bottom.equalTo(self.contentView);
        }];
        [self.decorate mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.bgView);
            make.top.equalTo(self.bgView.mas_top);
            make.height.mas_equalTo(25);
        }];
        [self.iv mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.bgView).offset(28+25);
            make.centerX.equalTo(self.bgView);
            make.width.mas_equalTo(253);
            make.height.mas_equalTo(160);
        }];
        [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.iv.mas_bottom).offset(27);
            make.centerX.equalTo(self.bgView);
            make.height.mas_equalTo(22);
        }];
        [self.subtitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgView).inset(15);
            make.top.equalTo(self.title.mas_bottom).offset(22);
            make.height.mas_equalTo(18);
        }];
        [self.clauseView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.bgView).inset(15);
            make.top.equalTo(self.subtitle.mas_bottom).offset(20);
            make.bottom.equalTo(self.bgView).inset(59);
        }];
        
        NSArray *texts = @[
            @"1、Turn off your camera's flash and make sure there's nothing in front of your ID card.",
            @"2、Put the ID card in the frame, with plenty of room on each side.",
            @"3、Turn off your camera's flash and make sure there's nothing in front of your ID card."
        ];
        NSMutableArray *arr = [NSMutableArray array];
        for (NSString *text in texts) {
            UILabel *label = [self clauseLabelWithText:text];
            [self.clauseView addSubview:label];
            [arr addObject:label];
        }
        [arr mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedSpacing:14 leadSpacing:0 tailSpacing:0];
        [arr mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.clauseView);
        }];
    }
    return self;
}

- (void)setTexts:(NSArray<NSString *> *)texts {
    _texts = texts;
    [self.clauseView removeAllSubviews];
    NSMutableArray *arr = [NSMutableArray array];
    for (NSString *text in texts) {
        UILabel *label = [self clauseLabelWithText:text];
        [self.clauseView addSubview:label];
        [arr addObject:label];
    }
    [arr mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedSpacing:14 leadSpacing:0 tailSpacing:0];
    [arr mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.clauseView);
    }];
}

- (SLCircleTitleComponent *)titleView {
    if (!_titleView) {
        _titleView = [SLCircleTitleComponent new];
        _titleView.titleLabel.text = @"Id Card Portrait Face Photo";
        _titleView.themeColor = UIColorHex(#1B1B1B);
    }
    return _titleView;
}
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.layer.cornerRadius = 20;
        _bgView.layer.borderColor = UIColorHex(#1B1B1B).CGColor;
        _bgView.layer.borderWidth = 1.5;
    }
    return _bgView;
}
- (UIImageView *)decorate {
    if (!_decorate) {
        _decorate = [UIImageView new];
        _decorate.contentMode = UIViewContentModeScaleAspectFit;
        _decorate.image = [UIImage imageNamed:@"icon_circle_bar"];
    }
    return _decorate;
}
- (UIImageView *)iv {
    if (!_iv) {
        _iv = [UIImageView new];
        _iv.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _iv;
}
- (UILabel *)title {
    if (!_title) {
        _title = [UILabel new];
        _title.text = @"Certification Requirement";
        _title.textColor = UIColorHex(#1B1B1B);
        _title.font = aspectDefaultFont(16);
        _title.textAlignment = NSTextAlignmentCenter;
    }
    return _title;
}
- (UILabel *)subtitle {
    if (!_subtitle) {
        _subtitle = [UILabel new];
        _subtitle.text = @"Scan In A Well-Lit Area.";
        _subtitle.textColor = UIColorHex(#1B1B1B);
        _subtitle.font = aspectBoldFont(14);
    }
    return _subtitle;
}
- (UIView *)clauseView {
    if (!_clauseView) {
        _clauseView = [UIView new];
    }
    return _clauseView;
}

- (UILabel *)clauseLabelWithText:(NSString *)text {
    UILabel *label = [UILabel new];
    label.numberOfLines = 0;
    label.text = @"1、Turn off your camera's flash and make sure there's nothing in front of your ID card.";
    label.textColor = UIColorHex(#666666);
    label.font = aspectDefaultFont(14);
    return label;
}

@end
